<!--
 * @Author: xuchen <xu.chen@ustcinfo.com>
 * @Date: 2025-03-13 16:38
 * @LastEditors: xuchen <xu.chen@ustcinfo.com>
 * @LastEditTime: 2025-03-13 16:38
 * @Description：HomePageLogin.vue
 * Copyright (c) 2024-present HBIS Digital Technology Co.,Ltd. All rights reserved.
 -->
<template lang="pug">
div
  button(@click="this.logout") 登出
  button(@click="this.routeToLogin") {{ isLogin }}
</template>
<script setup lang="ts">
import {getToken, removeToken} from "@/utils/auth";
import { reactive, getCurrentInstance } from 'vue'
// @ts-ignore
import store from "@/store";

const {proxy} = getCurrentInstance() as any
let isLogin: string = getToken() ? '已登陆' : '去登录'
const data = reactive({
  store,
  isLogin,
  logout,
  routeToLogin,
})
function logout() {
  removeToken()
  localStorage.removeItem('user')
  store.commit('user/removeUser') // 清除用户
  store.commit('core/setRouteAuth', []) // 清除菜单列表
  store.commit('core/updateDynamicCreateRoute', false)
  proxy.$router.push({name: 'home'})
  proxy.$message.success('已登出')
  data.isLogin = '去登录'
}
function routeToLogin() {
  proxy.$router.push({name: 'login'})
}
</script>

<style lang="scss" scoped>

</style>
